//
//  WmcHookEdgeLabel.swift
//  YPWatermarkCamera
//
//  Created by 赵新 on 2022/4/6.
//

import UIKit

class WmcHookEdgeLabel: UILabel {
    var borderWidth: CGFloat = 3 {
        didSet { layoutIfNeeded() }
    }
    
    var borderColor: UIColor = .white {
        didSet { layoutIfNeeded() }
    }

    override func drawText(in rect: CGRect) {
        let shadowOffset = shadowOffset
        let textColor = textColor

        guard let context = UIGraphicsGetCurrentContext() else { return }
        context.setLineWidth(borderWidth)
        context.setLineJoin(.round)

        context.setTextDrawingMode(.stroke)
        self.textColor = borderColor
        super.drawText(in: rect)

        context.setTextDrawingMode(.fill)
        self.textColor = textColor
        self.shadowOffset = CGSize(width: 0, height: 0)
        super.drawText(in: rect)

        self.shadowOffset = shadowOffset
    }
}
